// 封装发送请求

const BASE_URL = "http://localhost:8000/v1"
export const myRequest = (options) => {
	// 返回一个Promise resolve 成功时回调， reject 失败时回调
	return new Promise((resolve, reject)=>{
		uni.request({
			url: BASE_URL + options.url,
			method: options.method || 'GET',
			data: options.data || {},
			success(res) {
				if (res.data.status !== 0) {
					uni.showToast({
						title: '获取数据失败'
					})
				}
				console.log(res)
				resolve(res)
			},
			fail(err) {
				console.log(err)
				uni.showToast({
					title: '服务器错误'
				})
				reject(err)
			}
		})
	})
}